From: richard@nmr.ion.bpmf.ac.uk (Mr Richard Maunder)
Subject: Problems with "multiple defined" at linking stage
Sender: news@ucl.ac.uk (Usenet News System)
Message-ID: <1996Mar6.144651.26841@ucl.ac.uk>
Date: Wed, 6 Mar 1996 14:46:51 GMT
Reply-To: richard@nmr.ion.bpmf.ac.uk
Organization: Institute of Neurology NMR Research Unit, London, UK
Keywords: C++,C,header
I am trying to build a C++ patch over a C function library, but am encountering some problems at the linking stage, where the ld reports :
collect2: ld returned 2 exit status
ld: /usr/tmp/cca176282.o: __imerrbuf: multiply defined
I presume this is caused by a multiple include in the code, but I cannot see a way round it. The compiler (g++) makes no complaints when creating the object code.
The files I have are :
1) unc_c++_patch .h - The header for the patch. This had the standard :
#ifndef UNC_CPLUSPLUS_PATCH
#define UNC_CPLUSPLUS_PATCH
extern "C" {
#include "image.h"
}
......protyping for C++ methods.
#endif
in it. The file image.h is the header for the C function library.
2) unc_c++_patch.cc - The methods for the C++ patch. Has a #include unc_c++_patch.h at the top.
3) simple.cc - The actual program - again has unc_c++_patch.h at top.
I presume I should be able to compile unc_c++_patch.cc and simple.cc seperately and then link them, but won't the compiler include "image.h" both times - or is this the linkers job to sort this out ?? Even if I pass both .cc files to the compiler at the same time I get the same result.
I hope that I'm not being too stupid ! Any help gartefully recieved...Please CC tany replies o my e-mail address.